

#ifndef _ucedads_h
#define _ucedads_h 1

#ifdef __cplusplus
    #include "zAdesk.h"
#endif

#include "zadsdef.h"
#include "zaccoredefs.h"
#include "zacbasedefs.h"
#include "zacmem.h"
#include "zAdAChar.h"

#pragma pack (push, 8)

#ifdef ZdInt32
#undef ZdInt32
#endif
#ifndef __cplusplus
#define ZdInt32 ZSoft::Int32
#else
#define ZdInt32 long
#endif

const ZTCHAR*         ucedGetAppName ();
int            ucedUpdate(int vport, zds_point p1, zds_point p2);

#if defined(_WINDEF_) || !defined(_ZSOFT_WINDOWS_)

HWND           zdsw_ucadMainWnd();
#ifndef zdsw_hwndUcad
#define zdsw_hwndUcad zdsw_ucadMainWnd()
#endif

UCCORE_PORT HWND           zdsw_ucadDocWnd();

#endif  

int            ucedCommand (int rtype, ...);
int            ucedCmd (const struct resbuf *rbp);

int            ucedRegFunc (int (*fhdl) (void), int fcode);

int            ucedUsrBrk (void);

int            ucedDefun (const ZTCHAR *sname, int funcno);

int			   ucedDefunEx(const ZTCHAR * globalName, const ZTCHAR * localName, int fcode);

int            ucedSetFunHelp (const ZTCHAR* pszFunctionName,
                               const ZTCHAR* pszHelpfile,
                               const ZTCHAR* pszTopic, int iCmd);

int            ucedUndef (const ZTCHAR *sname, int funcno);

int            ucedGetFunCode (void);
struct resbuf *ucedGetArgs (void);

int            ucedRetList (const struct resbuf *rbuf);
int            ucedRetVal (const struct resbuf *rbuf);
int            ucedRetPoint (const zds_point pt);
int            ucedRetStr (const ZTCHAR *s);
int            ucedRetName (const zds_name aname, int type);
int            ucedRetInt (int ival);
int            ucedRetReal (zds_real rval);
int            ucedRetT (void);
int            ucedRetNil (void);
int            ucedRetVoid (void);

int            ucedEntSel (const ZTCHAR *str, zds_name entres,
                             zds_point ptres);
int            ucedNEntSel (const ZTCHAR *str, zds_name entres,
                              zds_point ptres, zds_point xformres[4],
                              struct resbuf **refstkres);
int            ucedNEntSelP (const ZTCHAR *str, zds_name entres,
                              zds_point ptres, int pickflag,
                              zds_matrix xformres,
                              struct resbuf **refstkres);
int            ucedSSGet (const ZTCHAR *str, const void *pt1,
                            const void *pt2, const struct resbuf *filter,
                            zds_name ss);
int            ucedSSGetFirst (struct resbuf** gset, struct resbuf** pset);
int            ucedSSSetFirst (const zds_name pset, const zds_name unused);
int            ucedSSFree (const zds_name sname);
int            ucedSSLength (const zds_name sname, ZdInt32 *len);
int            ucedSSAdd (const zds_name ename, const zds_name sname,
                            zds_name result);
int            ucedSSDel (const zds_name ename, const zds_name ss);
int            ucedSSMemb (const zds_name ename, const zds_name ss);
int            ucedSSName (const zds_name ss, ZdInt32 i, zds_name entres);
int            ucedSSNameX (struct resbuf **rbpp, const zds_name ss,
                              const ZdInt32 i);
int            ucedSSGetKwordCallbackPtr(struct resbuf* (**pFunc)(const ZTCHAR*));
int            ucedSSSetKwordCallbackPtr(struct resbuf* (*pFunc)(const ZTCHAR*));
int            ucedSSGetOtherCallbackPtr(struct resbuf* (**pFunc)(const ZTCHAR*));
int            ucedSSSetOtherCallbackPtr(struct resbuf* (*pFunc)(const ZTCHAR*));

int            ucedTrans (const zds_point pt, const struct resbuf *from,
                            const struct resbuf *to, int disp,
                            zds_point result);

int            ucedSetVar (const ZTCHAR *sym, const struct resbuf *val);
int            ucedInitGet (int val, const ZTCHAR *kwl);

int            ucedGetSym (const ZTCHAR *sname, struct resbuf **value);
int            ucedPutSym (const ZTCHAR *sname, struct resbuf *value);

int            ucedHelp (const ZTCHAR* szFilename, const ZTCHAR* szTopic, int iCmd);
int            ucedFNSplit (const ZTCHAR *pathToSplit, 
							ZTCHAR *prebuf, size_t nPreBufLen,
                            ZTCHAR *namebuf, size_t nNameBufLen,
							ZTCHAR *extbuf, size_t nExtBufLen);

#define HELP_CONTENTS     0x0003L  
#define HELP_HELPONHELP   0x0004L  
#define HELP_PARTIALKEY   0x0105L  

struct resbuf  *ucedZrxLoaded (void);
int            ucedZrxLoad (const ZTCHAR *app);
int            ucedZrxUnload (const ZTCHAR *app);

int            ucedInvoke (const struct resbuf *args,
                             struct resbuf **result);

int            ucedGetVar (const ZTCHAR *sym, struct resbuf *result);
int            ucedFindFile (const ZTCHAR *fname, ZTCHAR *result, size_t nBufLen);

int            ucedGetEnv (const ZTCHAR *sym, ZTCHAR  *var, size_t nBufLen);
int            ucedSetEnv (const ZTCHAR *sym, const ZTCHAR *val);

int            ucedGetCfg (const ZTCHAR *sym, ZTCHAR  *var, size_t len);
int            ucedSetCfg (const ZTCHAR *sym, const ZTCHAR *val);

int            ucedGetString (int cronly, const ZTCHAR *prompt, ZTCHAR *result, size_t bufsize);
int            ucedGetStringB (int cronly, const ZTCHAR *prompt,
                                    ZTCHAR *result, size_t bufsize);

int            ucedMenuCmd (const ZTCHAR *str);
int            ucedPrompt (const ZTCHAR *str);
int            ucedAlert (const ZTCHAR *str);

int            ucedGetAngle (const zds_point pt, const ZTCHAR *prompt,
                               zds_real *result);
int            ucedGetCorner (const zds_point pt, const ZTCHAR *prompt,
                                zds_point result);
int            ucedGetDist (const zds_point pt, const ZTCHAR *prompt,
                              zds_real *result);
int            ucedGetOrient (const zds_point pt, const ZTCHAR *prompt,
                                zds_real *result);
int            ucedGetPoint (const zds_point pt, const ZTCHAR *prompt,
                               zds_point result);
int            ucedGetInt (const ZTCHAR *prompt, int *result);
int            ucedGetKword (const ZTCHAR *prompt, ZTCHAR *result, size_t nBufLen);
int            ucedGetReal (const ZTCHAR *prompt, zds_real *result);
int            ucedGetInput (ZTCHAR *str, size_t nBufLen);
int            ucedVports (struct resbuf **vlist);

int            ucedTextScr (void);
int            ucedGraphScr (void);
int            ucedTextPage (void);

int            ucedRedraw (const zds_name ent, int mode);
int            ucedOsnap (const zds_point pt, const ZTCHAR *mode,
                            zds_point result);
int            ucedGrRead (int track, int *type, struct resbuf *result);
int            ucedGrText (int box, const ZTCHAR *text, int hl);
int            ucedGrDraw (const zds_point from, const zds_point to,
                             int color, int hl);
int            ucedGrVecs (const struct resbuf *vlist, zds_matrix mat);
int            ucedXformSS (const zds_name ssname,
                              zds_matrix genmat);
int            ucedDragGen (const zds_name ss, const ZTCHAR *pmt, int cursor,
                              int (*scnf) (zds_point pt, zds_matrix mt),
                              zds_point p);
int            ucedSetView (const struct resbuf *view, int vport);

int            ucedGetFileD (const ZTCHAR *title, const ZTCHAR *defawlt,
                               const ZTCHAR *ext, int flags,
                               struct resbuf *result);
int            ucedGetFileNavDialog (const ZTCHAR *title, const ZTCHAR *defawlt,
                             const ZTCHAR *ext, const ZTCHAR *dlgname, int flags,
                             struct resbuf **result);

int            ucedTextBox (const struct resbuf *args,
                              zds_point pt1, zds_point pt2);

int            ucedTablet  (const struct resbuf *args,
                              struct resbuf **result);

int            ucedGetCName (const ZTCHAR *cmd, ZTCHAR **result);

int           ucedEatCommandThroat(void);
int            ucdbEntDel (const zds_name ent);
struct resbuf *ucdbEntGetX (const zds_name ent, const struct resbuf *args);
struct resbuf *ucdbEntGet (const zds_name ent);
int            ucdbEntLast (zds_name result);
int            ucdbEntNext (const zds_name ent, zds_name result);
int            ucdbEntUpd (const zds_name ent);
int            ucdbEntMod (const struct resbuf *ent);
int            ucdbEntMake (const struct resbuf *ent);
int            ucdbEntMakeX (const struct resbuf *entm, zds_name result);
int            ucdbRegApp (const ZTCHAR *appname);
struct resbuf *ucdbTblNext (const ZTCHAR *tblname, int rewind);
struct resbuf *ucdbTblSearch (const ZTCHAR *tblname, const ZTCHAR *sym,
                              int setnext);
int	           ucdbNamedObjDict (zds_name result);
struct resbuf *ucdbDictSearch (const zds_name dict, const ZTCHAR* sym,
                               int setnext);
struct resbuf *ucdbDictNext (const zds_name dict, int rewind);
int            ucdbDictRename (const zds_name dictname, const ZTCHAR* oldsym,
                               const ZTCHAR* newsym);
int            ucdbDictRemove (const zds_name dictname, const ZTCHAR* symname);
int            ucdbDictAdd (const zds_name dictname, const ZTCHAR* symname,
                            const zds_name newobj);

int            ucdbTblObjName (const ZTCHAR *tblname, const ZTCHAR *sym,
                               zds_name result);

int            ucdbAngToS (zds_real v, int unit, int prec, ZTCHAR *str, size_t nBufLen);
int            ucdbRawAngToS (zds_real v, int unit, int prec, ZTCHAR *str, size_t nBufLen);
int            ucdbRToS (zds_real val, int unit, int prec, ZTCHAR *str, size_t nBufLen);
int            ucdbAngToF (const ZTCHAR *str, int unit, zds_real *v);
int            ucdbRawAngToF (const ZTCHAR *str, int unit, zds_real *v);
int            ucdbDisToF (const ZTCHAR *str, int unit, zds_real *v);
int            ucdbInters (const zds_point from1, const zds_point to1,
                             const zds_point from2, const zds_point to2,
                             int teston, zds_point result);
int            ucdbSNValid (const ZTCHAR *tbstr, int pipetest);
int			   zds_queueexpr(const ZTCHAR* pchString);

void		   ucedRegen();


#ifdef __cplusplus

int            ucedGetFullInput(ZTCHAR *&pStr);
int            ucedGetFullKword(const ZTCHAR * pString, ZTCHAR *&pStr);
int            ucedGetFullString(int cronly, const ZTCHAR *pString,
                                 ZTCHAR *&pResult);
int            ucedSSNameXEx (struct resbuf **rbpp, const zds_name ss,
                              const ZdInt32 i, unsigned int flags = 0);

template<size_t nBufLen> inline 
int ucedGetEnv(const ZTCHAR* pszName, ZTCHAR (&buf)[nBufLen])
{
	return ::ucedGetEnv(pszName, buf, nBufLen);
}

template<size_t nBufLen> inline 
int ucedGetInput(ZTCHAR (&buf)[nBufLen])
{
	return ::ucedGetInput(buf, nBufLen);
}

template<size_t nBufLen> inline 
int ucedGetString(int cronly, const ZTCHAR* prompt, ZTCHAR (&buf)[nBufLen])
{
	return ::ucedGetString(cronly, prompt, buf, nBufLen);
}

template<size_t nBufLen> inline 
int ucedFindFile(const ZTCHAR* pszName, ZTCHAR (&buf)[nBufLen])
{
	return ::ucedFindFile(pszName, buf, nBufLen);
}

template<size_t nBufLen> inline 
int ucedGetKword(const ZTCHAR* pszPrompt, ZTCHAR (&buf)[nBufLen])
{
	return ::ucedGetKword(pszPrompt, buf, nBufLen);
}

template<size_t nPreBufLen, size_t nNameBufLen, size_t nExtBufLen> inline 
int	ucedFNSplit(const ZTCHAR* pathToSplit,
	ZTCHAR (&prebuf) [nPreBufLen],
	ZTCHAR (&namebuf)[nNameBufLen],
	ZTCHAR (&extbuf) [nExtBufLen])
{
	return ::ucedFNSplit(pathToSplit, prebuf, nPreBufLen, namebuf, nNameBufLen,	extbuf, nExtBufLen);
}

template<size_t nNameBufLen> inline 
int ucedFNSplit(const ZTCHAR* pathToSplit, size_t nPre, ZTCHAR (&namebuf)[nNameBufLen], size_t nExt)
{
	return ::ucedFNSplit(pathToSplit, nullptr, nPre, namebuf, nNameBufLen, nullptr, nExt);
}

template<size_t nExtBufLen> inline 
int ucedFNSplit(const ZTCHAR*pathToSplit, size_t nPre, size_t nName, ZTCHAR(&extbuf)[nExtBufLen])
{
	return ::ucedFNSplit(pathToSplit, nullptr, nPre, nullptr, nName, extbuf, nExtBufLen);
}

template<size_t nNameBufLen, size_t nExtBufLen> 
inline int ucedFNSplit(const ZTCHAR* pathToSplit, size_t nPre, ZTCHAR (&namebuf)[nNameBufLen], ZTCHAR(&extbuf)[nExtBufLen])
{
	return ::ucedFNSplit(pathToSplit, nullptr, nPre, namebuf, nNameBufLen, extbuf, nExtBufLen);
}

template<size_t nPreBufLen> 
inline int ucedFNSplit(const ZTCHAR*pathToSplit, ZTCHAR(& prebuf)[nPreBufLen], size_t nName, size_t nExt)
{
	return ::ucedFNSplit(pathToSplit, prebuf, nPreBufLen, nullptr, nName, nullptr, nExt);
}

template<size_t nBufLen> 
inline int ucdbAngToS(zds_real v, int unit, int prec, ZTCHAR(& buf)[nBufLen])
{
	return ::ucdbAngToS(v, unit, prec, buf, nBufLen);
}

template<size_t nBufLen> 
inline int ucdbRawAngToS(zds_real v, int unit, int prec, ZTCHAR(& buf)[nBufLen])
{
	return ::ucdbRawAngToS(v, unit, prec, buf, nBufLen);
}

template<size_t nBufLen> 
inline int ucdbRToS(zds_real v, int unit, int prec, ZTCHAR(& buf)[nBufLen])
{
	return ::ucdbRToS(v, unit, prec, buf, nBufLen);
}

//deprecated: The following method will be removed in future
int ucedFNSplit (const ZTCHAR *pathToSplit, ZTCHAR *prebuf, ZTCHAR *namebuf, ZTCHAR *extbuf);
int ucedFindFile (const ZTCHAR *fname, ZTCHAR *result);
int ucedGetEnv (const ZTCHAR *sym, ZTCHAR  *var);
int ucedGetCfg (const ZTCHAR *sym, ZTCHAR  *var);
int ucedGetString (int cronly, const ZTCHAR *prompt, ZTCHAR *result);
int ucedGetStringB (int cronly, const ZTCHAR *prompt, ZTCHAR *result);
int ucedGetKword (const ZTCHAR *prompt, ZTCHAR *result);
int ucedGetInput (ZTCHAR *str);
int ucdbAngToS (zds_real v, int unit, int prec, ZTCHAR *str);
int ucdbRawAngToS (zds_real v, int unit, int prec, ZTCHAR *str);
int ucdbRToS (zds_real val, int unit, int prec, ZTCHAR *str);

#endif  

#pragma pack (pop)

#endif  
